//this
//

//1) object -- that particular object key
//2) new keyword -- this -- empty object
//3) function declaration -- window
//4) call and apply on functions

//this inside an object
var person ={
    name : "john",
    age : 32,
    yearOfBirth: function(age,currentYear){

        //age -- 20
        //this.age -- 32
        return currentYear - this.age;
       // return 2015 - person.age
    }
}

console.log(person.yearOfBirth(20,2015));//1983

// 2) this inside  new keyword
var total = 100;
//3)function declaration

function Car(ownerValuePassed,colorValuePassed,total){
 //window
    this.owner = ownerValuePassed;
    this.color = colorValuePassed;
    this.total = total;
    //this -- global Object

}

var myCar = Car('john','green',2000);
console.log(total);//100,undefined,100
//2000
//---------call and apply

var jim = {
    name : 'jim',
    age : 35,
    calculateYOB: function(currentYear,eyeColor){
        //this -- rabbit
        return currentYear - this.age;
    }
}

jim.calculateYOB(2015,'black');//1980

var rabbit = {
    name : "sweety",
    age : 6

}
//scope of this
//fName.call(newThisValue,)

jim.calculateYOB.call(rabbit,2015,'black');//2009
jim.calculateYOB.apply(rabbit,[2015,'black']);//2009
var params = [2015,'black'];
jim.calculateYOB.apply(rabbit,params);//2009



